<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<!-- Mirrored from www.zi-han.net/theme/hplus/login_v2.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:19:49 GMT -->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/login.min.css" rel="stylesheet">


    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-7">
                <div class="signin-info">
                    <div class="logopanel m-b">
                        <h1>久零 <img src="${ctxStatic}/plugins/nic/assets/admin/layout/img/logo.png" alt="logo" class="logo-default"/></h1>
                    </div>
                    <div class="m-b"></div>
                    <h4>欢迎使用 <strong>江苏网之畅有限公司</strong></h4>
                    <ul class="m-b">
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势三</li>
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势四</li>
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势五</li>
                    </ul>
                    <strong>还没有账号？ <a href="#">立即注册&raquo;</a></strong>
                </div>
            </div>
            <div class="col-sm-5">
                <form id="formlogin" name="formlogin">
                    <h4 class="no-margins">登录：<img src="${ctxStatic}/plugins/nic/assets/admin/layout/img/logo.png" alt="logo" class="logo-default"/></h4>
                    <p class="m-t-md">登录本平台 <span id="loginerr"></span></p>
                    <input type="text" class="form-control uname" name="username" placeholder="用户名" />
                    <input type="password" class="form-control pword m-b" name="password" placeholder="密码" />
                    <a href="#">忘记密码了？</a>
                    <button type="button" onclick="submitUserList_3();" class="btn btn-success btn-block">登录</button>
                </form>

            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; 2016 All Rights Reserved. 江苏网之畅有限公司
            </div>
        </div>
    </div>
</body>
<script language="JavaScript" src="${ctxStatic}/plugins/h+/js/jquery.min.js" ></script>
<script language="JavaScript" src="${ctxStatic}/plugins/h+/js/jquery.json-2.4.js" ></script>
<script>
    //将表单序列化成json格式的数据(但不适用于含有控件的表单，例如复选框、多选的select)
    (function($){
        $.fn.serializeJson = function(){
            var jsonData1 = {};
            var serializeArray = this.serializeArray();
            // 先转换成{"id": ["12","14"], "name": ["aaa","bbb"], "pwd":["pwd1","pwd2"]}这种形式
            $(serializeArray).each(function () {
                if (jsonData1[this.name]) {
                    if ($.isArray(jsonData1[this.name])) {
                        jsonData1[this.name].push(this.value);
                    } else {
                        jsonData1[this.name] = [jsonData1[this.name], this.value];
                    }
                } else {
                    jsonData1[this.name] = this.value;
                }
            });
            // 再转成[{"id": "12", "name": "aaa", "pwd":"pwd1"},{"id": "14", "name": "bb", "pwd":"pwd2"}]的形式
            var vCount = 0;
            // 计算json内部的数组最大长度
            for(var item in jsonData1){
                var tmp = $.isArray(jsonData1[item]) ? jsonData1[item].length : 1;
                vCount = (tmp > vCount) ? tmp : vCount;
            }

            if(vCount > 1) {
                var jsonData2 = [];
                for(var i = 0; i < vCount; i++){
                    var jsonObj = {};
                    for(var item in jsonData1) {
                        jsonObj[item] = jsonData1[item][i];
                    }
                    jsonData2.push(jsonObj);
                }
                return JSON.stringify(jsonData2);
            }else{
                return "[" + JSON.stringify(jsonData1) + "]";
            }
        };
    })(jQuery);




    function submitUserList_3() {
        var jsonStr = $("#formlogin").serializeJson();
        //var customerArray = new Array();
        //customerArray.push({username: "李四", password: "123"});
        //customerArray.push({username: "张三", password: "332"});
        $.ajax({
            //url: "${ctx}/user/login",
            url:"${ctx}/home/toHome",
            type: "POST",
            contentType : 'application/json;charset=utf-8', //设置请求头信息
            dataType:"json",
            //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
            data: jsonStr,//$.toJSON(customerArray),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
            success: function(data){
                if(data.success==true){
                   //跳转首页
                    window.location.href="${ctx}/home/toIndex";
                }else{
                    $("#loginerr").html('<h5 style="background-color: darkred">登录失败！</h5>');
                }
            },
            error: function(res){
                alert(res.msg);
            }
        });
    }
</script>

</html>
